﻿using System;
using System.Collections.Generic;
using System.Data;

using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;
//using Oracle.DataAccess.Types;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Oracle;

namespace DBQuery
{
    /// <summary>
    /// Summary description for ProfileSummaryTable
    /// </summary>
    public static class ProfileSummaryTable
    {
        public static int SaveProfileSummary(int iCustomerInfoTypeId, String sxText)
        {
            DBLib dbl = new DBLib();
            int iReturn = SaveProfileSummary(dbl, iCustomerInfoTypeId, sxText);
            
            return iReturn;
        }
        public static int SaveProfileSummary(DBLib dbl, int iCustomerInfoTypeId, String sxText)
        {
            List<OracleParameter> lsParams = new List<OracleParameter>();

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "out_new_id";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.Number;
            lsParams[lsParams.Count - 1].Direction = ParameterDirection.Output;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_P_CUSTOMER_INFO_TYPE_ID";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.Number;
            lsParams[lsParams.Count - 1].Value = iCustomerInfoTypeId;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_TEXT";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = sxText;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_CREATE_BY";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = ICPUser.ID;

            String sxQuery = "PR_INSERT_PROFILE_SUMMARY";

            dbl.ExecuteProcedure(sxQuery, lsParams.ToArray());

            return Convert.ToInt32(lsParams[0].Value);
        }

        public static void UpdateProfileSummary(int iProfileSummaryId, String sxText)
        {
            DBLib dbl = new DBLib();
            UpdateProfileSummary(dbl, iProfileSummaryId, sxText);
            
        }
        public static void UpdateProfileSummary(DBLib dbl, int iProfileSummaryId, String sxText)
        { 
            List<OracleParameter> lsParams = new List<OracleParameter>();

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_P_CUSTOMER_INFO_SUMMARY_ID";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.Number;
            lsParams[lsParams.Count - 1].Value = iProfileSummaryId;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_TEXT";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = sxText;

            lsParams.Add(new OracleParameter());
            lsParams[lsParams.Count - 1].ParameterName = "in_UPDATE_BY";
            lsParams[lsParams.Count - 1].OracleDbType = OracleDbType.VarChar;
            lsParams[lsParams.Count - 1].Value = ICPUser.ID;

            String sxQuery = "PR_UPDATE_PROFILE_SUMMARY";

            dbl.ExecuteProcedure(sxQuery, lsParams.ToArray());
        }

        public static void DeleteProfileSummary(int iProfileSummaryId)
        {
            DBLib dbl = new DBLib();
            DeleteProfileSummary(dbl, iProfileSummaryId);
            
        }
        public static void DeleteProfileSummary(DBLib dbl, int iProfileSummaryId)
        {
            List<OracleParameter> lsParams = new List<OracleParameter>();

            OracleParameter param = new OracleParameter();
            param.ParameterName = "prmID";
            param.OracleDbType = OracleDbType.Number;
            param.Value = iProfileSummaryId;

            String sxQuery = " delete from P_CUSTOMER_INFO_SUMMARY where P_CUSTOMER_INFO_SUMMARY_ID = :prmID";

            dbl.ExecuteNonQuery(sxQuery, param);
        }

        public static void ToggleProfileSummary(int iProfileSummaryId)
        {
            DBLib dbl = new DBLib();
            ToggleProfileSummary(dbl, iProfileSummaryId);
            
        }
        public static void ToggleProfileSummary(DBLib dbl, int iProfileSummaryId)
        {
            List<OracleParameter> lsParams = new List<OracleParameter>();

            OracleParameter param = new OracleParameter();
            param.ParameterName = "in_P_CUSTOMER_INFO_SUMMARY_ID";
            param.OracleDbType = OracleDbType.Number;
            param.Value = iProfileSummaryId;

            String sxQuery = "PR_TOGGLE_PROFILE_SUMMARY";

            dbl.ExecuteProcedure(sxQuery, param);
        }
    }
}